package com.ruoyi.blindBoxManage.mapper;

import com.ruoyi.blindBoxManage.domain.Box;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 盲盒箱子配置Mapper接口
 * 
 * @author ruoyi
 * @date 2025-08-12
 */
public interface BoxMapper 
{
    /**
     * 查询盲盒箱子配置
     * 
     * @param id 盲盒箱子配置主键
     * @return 盲盒箱子配置
     */
    public Box selectBoxById(Long id);

    /**
     * 查询盲盒箱子配置列表
     * 
     * @param box 盲盒箱子配置
     * @return 盲盒箱子配置集合
     */
    public List<Box> selectBoxList(Box box);

    /**
     * 新增盲盒箱子配置
     * 
     * @param box 盲盒箱子配置
     * @return 结果
     */
    public int insertBox(Box box);

    /**
     * 修改盲盒箱子配置
     * 
     * @param box 盲盒箱子配置
     * @return 结果
     */
    public int updateBox(Box box);

    /**
     * 删除盲盒箱子配置
     * 
     * @param id 盲盒箱子配置主键
     * @return 结果
     */
    public int deleteBoxById(Long id);

    /**
     * 批量删除盲盒箱子配置
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteBoxByIds(Long[] ids);

    @Select("select id from t_box where name = #{name}")
    Long selectIdByName(@Param("name") String name);

    @Select("select name from t_box where id = #{id}")
    String selectNameById(@Param("id") Long id);

    @Select("select count(*) from t_box where blind_box_id = #{blindBoxId}")
    Integer selectCountByBlindBoxId(@Param("blindBoxId") Long blindBoxId);

    @Select("select count(*) from t_box where blind_box_id = #{blindBoxId} and name = #{name}")
    Integer selectCountByBlindBoxIdAndBoxName(@Param("blindBoxId")Long blindBoxId,@Param("name") String name);
    @Select("select count(*) from t_box where blind_box_id = #{blindBoxId} and name = #{name} and id != #{id}")
    Integer selectCountByBlindBoxIdAndBoxNameAndId(@Param("blindBoxId")Long blindBoxId,@Param("name") String name, @Param("id") Long id);

    List<Box> selectListByBlindBoxId(@Param("blindBoxId")Long blindBoxId);

    @Select("select * from t_box where blind_box_id = #{blindBoxId}")
    List<Box> selectBoxListByBlindBoxId(@Param("blindBoxId")Long blindBoxId);

    Box selectLastBoxByBlindBoxId(@Param("blindBoxId")Long blindBoxId);
}
